#!/usr/bin/env python
#Boa:App:BoaApp

import wx



import dbmngr
from config import *
from product import *

from EventTimer import MyEventTimer

import FrameMain,DlgLogin,DlgUpdate

import permitManager

modules ={u'DlgLogin': [0, '', u'DlgLogin.py'],
 u'FrameMain': [1, 'Main frame of Application', u'FrameMain.py'],
 u'FramePayment': [0, '', u'FramePayment.py'],
 u'FramePro': [0, '', u'FramePro.py'],
 u'FrameSO': [0, '', u'FrameSO.py'],
 u'ctrl': [0, '', u'ctrl.py'],
 u'dbmngr': [0, '', u'dbmngr.py'],
 u'main': [0, '', u'main.py'],
 u'partner': [0, '', u'partner.py'],
 u'product': [0, '', u'product.py'],
 u'warehouse': [0, '', u'warehouse.py']}

class BoaApp(wx.App):
    def OnInit(self):
        Cfg.initCfg()
        
##        login = DlgLogin.create(None)
##        if (login.ShowModal() == wx.ID_CANCEL):
##            return False

        self.main = FrameMain.create(None)
        self.main.Show()
        self.SetTopWindow(self.main)
        
        #Must be child-Dlg, or else the prog cannot exit while main closed 
        login = DlgLogin.create(self.main)
        if (login.ShowModal() == wx.ID_CANCEL):
            return False
        
        #self.main.setMenuAccess()
            
        
##        if not(Cfg.checkVersion()):
##            login = DlgUpdate.create(self.main)
##            if (login.ShowModal() != wx.ID_OK):
##                return False
        
        timer = MyEventTimer(self.main)
        timer.start()
        
        return True

    def OnExit(self):
        print 'BoaApp exit'
        
def main():
    import myLogger    
    #rdrStdout.start()
    myLogger.initLogger()
    
        
    dbmngr.db_init()
##    dbmngr.db_tblInit(product.Product.strDbTblInit)
##    dbmngr.db_tblInit(partner.Partner.strDbTblInit)
    
    #product.loadPros()
##    CDataProduct.refreshDataList()
##    CDataCategory.refreshDataList()
##    CDataKeyword.refreshDataList()
##    CDataDelivery.refreshDataList()
    dataModelInit()
    
    permitManager.PermitManager.load()
    
    application = BoaApp(0)
    application.MainLoop()

if __name__ == '__main__':
    main()
